<extend name="./App/Common/View/default/Base/common.html" />
<block name="main_content">
    <include file="./App/Common/View/default/Public/crumb.html" />
    <div class="mod">
        <div class="mod-head">
            <h3>
                <ul class="nav nav-tabs">
                <li class="">
                        <a href="{:U('index')}">新闻管理</a>
                    </li>
                    <li class="active">
                        <a href="javascript:void()">新增新闻</a>
                    </li>
                </ul>
            </h3>
            
        </div>
        <style>
            .choose-box{
                position: absolute;
                top: -20%;
                left: -20%;
                display: block;
                width: 140%;
                height: 140%;
                margin: 0px;
                padding: 0px;
                background: rgb(255, 255, 255) none repeat scroll 0% 0%;
                border: 0px none; opacity: 0;
            }
           .list-items{
               margin-right: 20px;
           }
            .more-size{
                margin-bottom: 10px;
            }
            .form-group .col-sm-2{
                width:11%!important;
            }
            .form-group .col-sm-9{
                width:82%!important;
            }
            .col-sm-9 #edui1{
                width:100%!important;
            }
            .w-e-text-container{z-index:1!important;}
            .w-e-menu{z-index:2!important;}
        </style>
        <div class="tab-content mod-content clearfix">
            <form action="{:U('add')}" method="POST" enctype="multipart/form-data">
                <div class="form-group clearfix" style="">
                    <label class="col-sm-2 col-xs-3 control-label clearfix" style="text-align: right">新闻标题：</label>
                    <div class="col-sm-9 col-xs-12">
                        <input required="" class="form-control" type='text' name="title">
                    </div>
                </div>
                  <div class="form-group clearfix" style="">
                    <label class="col-sm-2 col-xs-3 control-label clearfix" style="text-align: right">来源：</label>
                    <div class="col-sm-9 col-xs-12">
                        <input required="" class="form-control" type='text' name="source">
                    </div>
                </div>
                <div class="form-group clearfix" style="">
                    <label class="col-sm-2 col-xs-3 control-label clearfix" style="text-align: right">此页面信息为：</label>
                    <div class="col-sm-9 col-xs-12">
                        <input required="" class="form-control" type='text' name="business">
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 col-xs-3 control-label clearfix" style="text-align: right">图片：</label>
                    <div class="col-sm-9 col-xs-12" ng-invoker="context.bind();">
                        <div class="input-group ">
                            <input required="" name="picture" class="form-control webuploader-input" value="" type="text">
                            <span class="input-group-btn">
                                <button class="btn btn-default webuploader-btn" type="button" data-toggle="modal" data-target="#modal-wechat-webuploader" style="height: 34px; width:100%;">选择图片</button>
                            </span>
                        </div>
                        <div class="input-group " style="margin-top:.5em;">
                            <img src="/Public/Mp/img/nopic.jpg" data-nopic="/Public/Mp/img/nopic.jpg" class="img-responsive img-thumbnail webuploader-picture" width="150">
                            <em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片">×</em>
                        </div>
                    </div>
                </div>
                <div class="form-group clearfix" style="">
                    <label class="col-sm-2 col-xs-3 control-label clearfix" style="text-align: right">简介：</label>
                    <div class="col-sm-9 col-xs-12">
                        <input required="" class="form-control" type='text' name="desc">
                    </div>
                </div>
                <div class="form-group clearfix" style="">
                    <label class="col-sm-2 col-xs-3 control-label clearfix" style="text-align: right">内容：</label>
                    <div class="col-sm-9 col-xs-12">
                        <!-- <input class="form-control" type='text' name="title"> -->
                        <div id="editor"></div>
                        <textarea name="content" style="display:none" id="text1" style="width:100%; height:200px;"></textarea>
                        <script type="text/javascript" src="https://unpkg.com/wangeditor@3.1.1/release/wangEditor.min.js"></script>
                        <script type="text/javascript">
                            var E = window.wangEditor
                            var editor = new E('#editor')
                            // 或者 var editor = new E( document.getElementById('editor') )
                            //editor.customConfig.uploadImgServer = '/upload'
                            var $text1 = $('#text1')
                            editor.customConfig.onchange = function (html) {
                                // 监控变化，同步更新到 textarea
                                $text1.val(html)
                            }
                            editor.customConfig.uploadImgShowBase64 = true   // 使用 base64 保存图片
                             // 自定义菜单配置
                            editor.customConfig.menus = [
                            'head',  // 标题
                            'bold',  // 粗体
                            'fontSize',  // 字号
                            'fontName',  // 字体
                            'italic',  // 斜体
                            'underline',  // 下划线
                            'strikeThrough',  // 删除线
                            'foreColor',  // 文字颜色
                            'backColor',  // 背景颜色
                            'link',  // 插入链接
                            'list',  // 列表
                            'justify',  // 对齐方式
                            'quote',  // 引用
                            'image',  // 插入图片
                            'table',  // 表
                            'undo',  // 撤销
                            'redo'  // 重复
                            ]
                            editor.create()
                        </script>
                    </div>
                </div>
                <div class="form-group clearfix" style="text-align: center">
                    <input class="btn btn-primary" id="submit" value="确  认" type="submit">
                    <input class="btn btn-primary"  type="reset" value='重 置'/>
                </div>
            </form>
        </div>
    </div>
</block>
<block name="script">
    <script src="__PUBLIC__/Admin/js/plupload.full.min.js"></script>
    <script src="https://unpkg.com/qiniu-js@v2.2.2/dist/qiniu.min.js"></script>
    <script type="text/javascript">  
        var moreTypeChoose = $('#more-type-choose');
        moreTypeChoose.hide();
        $('.choose-box').on('ifChecked', function (e){
            var val = $(this).val();
            if(val == 1){
                moreTypeChoose.slideDown();
            }else{
                moreTypeChoose.slideUp();
            }

        });

        var choosePay = $('.choose-pay');
        choosePay.on('change',function(){

            var value = $(this).val();
            $('.choose-pay-type').hide();
            
                if(value != 1){
                    $('.zhf').show();
                    $('.dianlei').hide();
                }else{
                    $('.zhf').show();
                    $('.dianlei').show();
                }
                $(this).find('input[type="number"]').val("");
            
        })

        //优惠类型修改
        var cheapType = $('.cheaper-type');
        $('.che-type').on('change',function(){
            console.log($(this).val());

            if($(this).val() === '1'){

                cheapType.each(function(){
                    if($(this).attr('data-type') === 'dazhe'){
                        $(this).show();
                    }else {
                        $(this).hide();
                    }
                })
            }else {
                cheapType.each(function(){
                    if($(this).attr('data-type') === 'jiage'){
                        $(this).show();
                    }else {
                        $(this).hide();
                    }
                })
            }
        })

        $('.yhj').change(function(){
            var yj = $('.y_price').val();
            var zhk = $('.yhj').val();
            var zhh = yj*(zhk/10);
            $('.yhh').val(zhh); 
        });
    </script>

    <script>
        $(function(){
            //上传视频
        var $uploading = true;
        $('.upload-video').on('change',function(){
            // var timestamp = new Date().getTime();
            // num = Math.random()*700 + 800;
            // keys = 'video'+timestamp+parseInt(num, 10)+'.'+arr_url[lengths-1];
            if(!$uploading){
                layer.message({
                    content:'视频上传中，请稍后...',
                    time:1
                });
                return;
            }
            $uploading = false;
            var _self = $(this),
                file = _self[0].files[0],
                token = null,
                domain = null,
                config = null,
                putExtra = {};
            var arr_url = file.name.split('.');
            var lengths = arr_url.length;
           $.ajax({
               url:"{:U('qiniu')}",
               type:"get",
               success:function(res){
                   console.log(res);
                   token = res.uptoken;//验证token
                   domain = res.domain;//访问绑定域名
                   config = {
                       useCdnDomain: true, //表示是否使用 cdn 加速域名，为布尔值，true 表示使用，默认为 false。
                       disableStatisticsReport: false, //是否禁用日志报告，为布尔值，默认为false。
                       retryCount: 6, //上传自动重试次数（整体重试次数，而不是某个分片的重试次数）；默认 3 次（即上传失败后最多重试两次）；目前仅在上传过程中产生 599 内部错误时生效，但是未来很可能会扩展为支持更多的情况。
                       region: qiniu.region.z1,  //选择上传域名区域；当为 null 或 undefined 时，自动分析上传域名区域
                   };
                   putExtra = {
                       fname: file.name,//fname: string，文件原文件名
                       params: {},
                       //params: object，用来放置自定义变量
                       mimeType: null //null || array，用来限制上传文件类型，为 null 时表示不对文件类型限制；限制类型放到数组里： ["image/png", "image/jpeg", "image/gif"]
                   };
                   var timestamp = new Date().getTime();
                   var num = Math.random()*700 + 800;
                   keys = 'video'+timestamp+parseInt(num, 10)+'.'+arr_url[lengths-1];
                   var observable = qiniu.upload(file, keys, token, putExtra, config);
                   observable.subscribe({
                       next:function(res){
                           console.log(res.total.percent)
                           var percent = res.total.percent.toFixed(2);
                           _self.siblings('span').text('视频上传'+percent+'%')
                       },
                       error:function(res){
                           _self.siblings('span').text('上传失败')
                           $uploading = true;
                       },
                       complete:function(res){
                        console.log(res)
                            _self.siblings('span').text('上传成功');
                            $('.domain').val(domain+'/'+res.key)
                           $uploading = true;
                       }
                   })
               }
           })
        });
        })
    </script>
</block>